package br.com.eduquiz.session;

import java.util.ArrayList;
import java.util.List;

import br.com.eduquiz.entity.*;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityHome;

@Name("categoriaHome")
public class CategoriaHome extends EntityHome<Categoria> {

	private static final long serialVersionUID = 585802069725258668L;

	@In(create = true)
	UsuarioHome usuarioHome;

	public void setCategoriaId(Long id) {
		setId(id);
	}

	public Long getCategoriaId() {
		return (Long) getId();
	}

	@Override
	protected Categoria createInstance() {
		Categoria categoria = new Categoria();
		return categoria;
	}

	public void load() {
		if (isIdDefined()) {
			wire();
		}
	}

	public void wire() {
		getInstance();
		Usuario usuario = usuarioHome.getDefinedInstance();
		if (usuario != null) {
			getInstance().setUsuario(usuario);
		}
	}

	public boolean isWired() {
		return true;
	}

	public Categoria getDefinedInstance() {
		return isIdDefined() ? getInstance() : null;
	}
	
	public List<Questionario> getQuestionario() {
		return getInstance().getQuestionario() == null ? null : new ArrayList<Questionario>(
				getInstance().getQuestionario());
	}

}
